/**      .----.
*       _.'__    `.
*   .--($)($$)---/#\
* .' @          /###\
* :         ,   #####
*  `-..__.-' _.-\###/
*        `;_:    `"'
*      .'"""""`.
*     /,     ,\\
*    //  !BUG  \\
*    `-._______.-'
*    ___`. | .'___
*   (______|______)
*
* 首页-JS
* @author jon
* @email 191777962@qq.com
*/
$(function(){
    $('.alltype').mouseover(function(){
        $('.m-sub-nav').show();
    }).mouseout(function(){
        $('.m-sub-nav').hide();
    });
    $(window).on('scroll resize',function(){
        var width = document.body.clientWidth;
        if(width>=1240){
            if($(this).scrollTop()>350){
                $('.g-side').fadeIn('slow');
            }else{
                $('.g-side').hide();
            }
        }else{
            $('.g-side').hide();
        }
    });


    $("#j_notice").Xslider({
        effect: 'fade',
        content_box: "#j_notice_con",
        content_tag: ".m-notice-con",
        switcher_box: ".m-notice-tab",
        active_class: "z-sel",
        load_type: "textarea",
         isCheckShow: false
    });
    $("#j_banner").Xslider({
        effect: 'scrolly',
        auto: true,
        content_box: "#j_banner_tab",
        switcher_box: "#j_banner_con",
        active_class: "z-crt",
        index: "list",
        space: 6000,
        load_type: "img",
        isCheckShow: false
    });

    $("#j_link").Xslider({
        effect: 'fade',
        content_box: "#j_link_con",
        content_tag: ".brand-list-con",
        switcher_box: "#j_link_tab",
        active_class: "z-link-crt",
        isCheckShow: false
    });
    $("#j_update").Xslider({
        effect: 'fade',
        content_box: "#j_update_con",
        content_tag: ".m-update-con",
        switcher_box: ".m_update_tab",
        active_class: "z-crt",
        load_type: "img",
        isCheckShow: false
    });
    init();
});


function init() {
    var user = "";
    var htlm;
    //console.log(user);
    //console.log(user.name);
    wrap=$("#j_showlogin");

    if(user ==""){
        //console.log("未登录！")
        htlm='<img src="'+'img/tx.gif">'
            +'<div class="loginInfo">'
            +    '<h2>Hi，欢迎来到家居网！</h2>'
            +    '<p>您还未登录哦~</p>'
            +'</div>'
            +'<div class="login-btn">'
            +    '<a target="_self" class="u-btn login-icon" href="">登录</a>'
            +    '<a target="_self" class="u-btn" href="">免费注册</a>'
            +    '<a class="u-btn" href="">免费开店</a>'
            +'</div>';
    }else{

        htlm='<img src="'+static_url+'web/img/user-portrait.png">'
            +'<div class="loginInfo">'
            +   '<h2>您好！'+user.name+'</h2>'
            +   '<p>欢迎来到家居网</p>'
            +'</div>'
            +'<div class="login-btn-after">'
            +    '<a href="'+ user_url +'buyer/order" class="shopping">我的订单<b id="unpay"></b></a>'//(<em>4</em>)
            +    '<a href="'+ user_url +'" class="favorite">个人中心</a>'
            +    '<a href="'+ user_url +'message" class="note">我的消息<b id="unread"></b></a>'//(<em>2</em>)
            +'</div>'  ;

        //@author  首页未读消息和未支付数量
        $.getJSON("/home/user_stat?"+ (new Date()).getTime(),function(data){
               var unread=data.unread,
               unpay=data.unpay;
            if(unread>=100) {
               $("#unread").html("99");
            }else {
                $("#unread").html(unread);
            };
           if(unpay>=100){
            $("#unpay").html("99");
           }else{
                $("#unpay").html(unpay);
            }
        });

    }
    wrap.append(htlm);
}